var express = require("express");

var router = express.Router();

let { getTabs, addTab,getOne,getOneTabs,changeTab,remove} = require("../api/tabs.js");

router.get('/getOne/:navs_id',async function(req, res, next) {
    let {navs_id}=req.params;
    console.log(navs_id);
   let data= await getOne(navs_id);
   console.log(data, "tabs");
   res.send(data);
});
// 获取修改的那一条数据
router.get('/changeOne/:_id',async function(req, res, next) {
    // console.log("abc");
    let {_id}=req.params;
    console.log(_id);
   let data= await getOneTabs(_id);
   res.send(data);
});
// 修改信息
router.put("/change", async function (req, res, next) {
    console.log("in");
    const {_id,name} = req.body;
    console.log(_id,name);
    await changeTab({_id,name});
    res.send({ status: true });
});
// 删除
router.delete('/remove', async function (req, res, next) {
  console.log("router");
  const {_id} = req.body;
  console.log({_id},"routes");
  await remove({_id});
  res.send({ status: true })
});
//获取商品类型
router.get("/searchTabs", async function (req, res, next) {
  const { navsId } = req.query;
  const data = await getTabs(navsId);
  res.send(data);
});
//新增商品类型
router.post("/addTab", async function (req, res, next) {
  const { name, navsId } = req.body;
  // console.log({ name, navsId });
  const data = await addTab({ name, navsId });
  res.send(data);
});
module.exports = router;
